<?php
/**
 * 用户Model
 * @author solar
 */
class UserModel extends BaseModel 
{
	public static $name='`user`';
	public static $primary='u_id';
	
	public function __construct() {
		parent::__construct(CoreFactory::db(),self::$name,self::$primary);
	}
	
	/**
	 * 创建应用的用户
	 * @param int $sina_id 新浪ID
	 * @param string $user_name 用户名
	 * @param string $image_url 头像图片url
	 * @return $u_id 应用用户ID
	 * @author solar
	 */
	public function createAppUser($sina_id,$user_name,$image_url='') {
		$userRow['sina_id']=$sina_id;
		$userRow['u_user_name']=$user_name;
		$userRow['u_image_url']=$image_url;
		$userRow['u_create_time']=time();
		return ModelFactory::get('UserModel')->insert($userRow);
	}
	
	/**
	 * get user info by sina id
	 * @author solar
	 * @param int $sina_id
	 * @return array
	 */
	public function getBySinaID($sina_id) {
		return $this->getByField(array('sina_id'=>$sina_id));
	}
	
	/**
	 * 更新用户登录状态
	 * @author solar
	 * @param int $u_id
	 * @return void
	 */
	public function updateLoginStatus($u_id) {
		$sql="UPDATE ".self::$name." SET u_login_count=u_login_count+1,u_login_time='".time()."' WHERE u_id=".$u_id." LIMIT 1";
		$this->db->query($sql);
	}
	
}

?>